package cn.com.homeyoda.aimate.aihealth.ui.activity;

import android.os.Bundle;
import android.util.Log;

import androidx.lifecycle.ViewModelProviders;

import com.wzq.mvvmsmart.event.StateLiveData;

import cn.com.homeyoda.aimate.aihealth.BR;
import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.app.AppViewModelFactory;
import cn.com.homeyoda.aimate.aihealth.base.BaseActivity;
import cn.com.homeyoda.aimate.aihealth.base.BaseViewModel;
import cn.com.homeyoda.aimate.aihealth.data.Repository;
import cn.com.homeyoda.aimate.aihealth.databinding.ActivityNetRequestTestBinding;
import cn.com.homeyoda.aimate.aihealth.ui.login.LoginViewModel;

public class NetRequestTestActivity extends BaseActivity<ActivityNetRequestTestBinding, BaseViewModel<Repository>> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_net_request_test;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public BaseViewModel<Repository> initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        //  使用了factory ,factory向LoginView里注入了数据仓库
        return ViewModelProviders.of(this, factory).get(NetworkTestModel.class);
    }

    @Override
    public void initData() {
        super.initData();


    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.stateLiveData.stateEnumMutableLiveData.observe(this,object -> {
            if (object == StateLiveData.StateEnum.Success){
                if (viewModel.stateLiveData.getValue() != null){
                    binding.tvResult.setText(viewModel.stateLiveData.getValue().toString());
                }
            }
        });


    }
}
